var regUsername = /^[0-9a-zA-Z_]{1,20}$/;
var regEmail = /[\w!#$%&'*+/=?^_`{|}~-]+(?:\.[\w!#$%&'*+/=?^_`{|}~-]+)*@(?:[\w](?:[\w-]*[\w])?\.)+[\w](?:[\w-]*[\w])?/;
var regPassword = /^[0-9a-zA-Z_]{1,20}$/;

/*
    * 消除error
    * */
function errorDisplay($item) {
    var $parent = $item.parent();
    var $message = $parent.find('.form-message');
    $message.addClass("hidden");
    setInputColor($parent,false);
}

/*
* 检查表单
* */
function checkForm($item,message) {
    var $parent = $item.parent();
    var text = $($parent.find('.form-label').find('label')[0]).text();
    var $message = $parent.find('.form-message');
    $message.text(text + message);
    $message.removeClass("hidden");
    // $item.focus();
    setInputColor($parent,true);
}

/*
* 设置文本框颜色
* */
function setInputColor($input, flag) {
    flag? $input.addClass("has-error"):$input.removeClass("has-error");
}

/*
* 时间戳转日期格式
* */
function formatDate(timestamp) {
    var date = new Date(timestamp);
    var y = date.getFullYear();
    var m = date.getMonth() + 1;
    m = m < 10 ? ('0' + m) : m;
    var d = date.getDate();
    d = d < 10 ? ('0' + d) : d;
    var h = date.getHours();
    h = h < 10 ? ('0' + h) : h;
    var minute = date.getMinutes();
    var second = date.getSeconds();
    minute = minute < 10 ? ('0' + minute) : minute;
    second = second < 10 ? ('0' + second) : second;
    return y + '/' + m + '/' + d+' '+h+':'+minute+':'+second;
}

var sysmessageTPL = "" +
    "                    <div class=\"message-item col-lg-12 col-md-12 col-sm-12 col-xs-12\">\n" +
    "                        <div class=\"col-lg-offset-1 col-lg-2 col-md-offset-1 col-md-2 col-sm-offset-1 col-sm-2 col-xs-offset-1 col-xs-2 item-left\">\n" +
    "                        </div>\n" +
    "                        <div class=\"col-lg-6  col-md-6 col-sm-6 col-xs-6 item-prompt\">\n" +
    "                            <div class=\"item-message\">\n" +
    "                                <div class=\"prompt\">系统提示</div>\n" +
    "                                <div class=\"content text-center\">\n" +
    "                                    <label class=\"ct-label\">\n" +
    "                                    </label>\n" +
    "                                </div>\n" +
    "                            </div>\n" +
    "                        </div>\n" +
    "                        <div class=\"col-lg-2 col-md-2 col-sm-2 col-xs-2 item-right\">\n" +
    "                        </div>\n" +
    "                    </div>";
var messageTPL = '' +
    '<div class="message-item col-lg-12 col-md-12 col-sm-12 col-xs-12">\n' +
    '    <div class="col-lg-offset-1 col-lg-2 col-md-offset-1 col-md-2 col-sm-offset-1 col-sm-2 col-xs-offset-1 col-xs-2 item-left">\n' +
    '    </div>\n' +
    '    <div class="col-lg-6  col-md-6 col-sm-6 col-xs-6 item-middle">\n' +
    '        <div class="item-message">\n' +
    '            <div class="date"></div>\n' +
    '            <div class="content">\n' +
    '                <label class="ct-label">\n' +
    '                </label>\n' +
    '            </div>\n' +
    '        </div>\n' +
    '    </div>\n' +
    '    <div class="col-lg-2 col-md-2 col-sm-2 col-xs-2 item-right">\n' +
    '    </div>\n' +
    '</div>';
var userTPL = '<div class="item-user text-center" >\n' +
    '            <img class="image-head img-circle" src="../static/image/head.jpg"/>\n' +
    '            <div>\n' +
    '                <label class="nick-name"></label>\n' +
    '            </div>\n' +
    '        </div>';